
import { _decorator, Component, Node, Vec3, Material } from 'cc';
import { HexMesh } from './HexMesh';
const { ccclass, property } = _decorator;

@ccclass('HexMeshGround')
export class HexMeshGround extends Component {

    @property({ displayName: "杰哥不要", tooltip: "格子大小" })
    grid_size = 1;
    @property({ displayName: "杰哥不要", tooltip: "格子列数" })
    column = 40;
    @property({ displayName: "杰哥不要", tooltip: "格子行数" })
    row = 40;
    @property(Material)
    hexMapMaterial:Material;


    start() {

        let outer = HexMesh.outer_radius = this.grid_size;
        let inner = outer * 0.866025404;
        for (let i = 0; i < this.column; i++) {
            for (let j = 0; j < this.row; j++) {
                let inst = new Node().addComponent(HexMesh);
                inst.init(this.hexMapMaterial);
                this.node.addChild(inst.node);
                let offet = j % 2 == 0 ? 0 : inner;
                inst.node.position = new Vec3(i * inner * 2 + offet, 0, j * outer * 1.5);
            }
        }
    }

}
